#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
int main()
{
	long long a,n,q,num=1;
	cin>>a>>n>>q;
	int ss=n,dd=a;
	while(n)
	{
		if(n&1)
		{
			num*=a;	
			num%=q;
		}
		n=n/2;
		a=a*a%q;
	}
	printf("%ld^%ld mod %ld=%d",dd,ss,q,num);
	return 0;
}